<?
@ session_start();

include_once("class.lib/db.class.php");
include_once("class.lib/user.class.php");
//include_once("class.lib/diplome.class.php");
//include_once("class.lib/cours.class.php");
include_once("class.lib/domaine.class.php");
include_once("class.lib/mention.class.php");
include_once("class.lib/aa_niveau.class.php");
include_once("class.lib/aa_projet.class.php");
include_once("class.lib/grade.class.php");

if(isset($_GET['id_ue'])){
	$code_ue=$_GET['id_ue'];
}else{
	$code_ue=$_SESSION['code'];
}


?>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="uploadify/swfobject.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>


<script type="text/javascript">


function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}
$(document).ready(function() {
var err=true;
var nb=0;
  
  
   $('#file_upload').remove();
  $('#in1').html('<input id="file_upload" name="file_upload" type="file" />');
  
  
  $('#file_upload').uploadify({
    'uploader'  : 'uploadify/uploadify.swf',
    'script'    : 'uploadify/uploadify.php',
	'cancelImg' : 'uploadify/cancel.png',
    'folder'    : 'uploads',
	'buttonText': 'Parcourir',
    'auto'      : false,
	'sizeLimit'   : 2000000,
	//'fileExt'   : '*.jpg;*.gif;*.png',
	'fileExt'   : '*.doc;*.pdf;*.html',
	'queueID' 	: 'custom-queue',
	'removeCompleted' : false,
	'onSelectOnce'   : function(event,data) {
			 // $('#status-message').text(data.filesSelected + ' files have been added to the queue.');
				},
	'onAllComplete'  : function(event,data) {
			if(err)  $('#status-message').html('<div id="status-message_1" ><img src="images/ok.png" />'+data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.'+'</div>');
			else    $('#status-message').html('<div id="status-message_2" ><img src="images/error.png" />Votre cv doit être au fromat :  *.doc;*.pdf;*.html '+'</div>');
		
			},
		

	'onSelect' : function (event, queueID, fileObj) {
					var ext = fileObj.name;
					ext = ext.substr(ext.length-3); //gets last 3 chars (extention type)
					var exts=new Array('doc','docx','pdf','html');
				
							if(inArray(ext,exts)==false)
							{
						
							//alert("Not a valid .TIFF file");
							$('#status-message').html('<div id="status-message_2" ><img src="images/error.png" />Votre cv doit être au fromat :  *.doc;*.pdf;*.html '+'</div>');
							//$('#status-message').text('0 files uploaded, ' +  ' file extension error.');alert('');
							err=false;
							
							$('#file_upload').uploadifyCancel(queueID);
							//$('#status-message').text('');
							
							//$jQuery('#file_upload').uploadifySettings('script','/uploadify/uploadify-x.php');
							return false;
							}
							err=true;
							$('#status-message').html('');
							return true;
					
					
					
					},	
		
		'onError'     : function (event,ID,fileObj,errorObj) {
			alert(errorObj.type + ' Error: ' + errorObj.info);
						}
	   
  });
  
  
		 $("#add").click(function(){
	
		 addpartenaire();
		 
		 }); 
});


function addpartenaire(){


	
$("#formID").validationEngine();

	$.ajax(
		{
			type:"POST",
			url: "equipe.add.action.php",  
			data: "nom="+$("input[name=nom]").val()+"&prenom="+$("input[name=prenom]").val()+"&email="+$("input[name=email]").val()+"&grade="+$("select[name=grade]").val()+"&specialite="+$("input[name=specialite]").val()+
			"&id_universite="+$("input[name=id_universite]").val()+
			"&WebSite="+$("input[name=WebSite]").val()+
			"&Adresse="+$("input[name=Adresse]").val()+
			"&Ville="+$("input[name=Ville]").val()+
			"&CodePostal="+$("input[name=CodePostal]").val()+
			"&NumMobile="+$("input[name=NumMobile]").val()+
			"&NumFax="+$("input[name=NumFax]").val()+
			"&fonction="+$("input[name=fonction]").val()+
			
		
			"&id_ue="+$("input[name=id_ue]").val()+
			"&tel="+$("input[name=tel]").val(),
			async:false,
			beforeSend: function(xhr){
				
            //    $("#message").html("<img src='../../images/loading_16X16.gif'/>");
            },
			success : function (data) {
				//alert(data);
				
				
				//$("#ajout").html("");
				//alert(data);
			$('#file_upload').uploadifySettings("scriptData", {'id_owner': data });
			$('#file_upload').uploadifyUpload();
				
			
				document.location="equipe.php?id_ue="+"<?php echo $code_ue; ?>";
				//	load_page('addequipe.php?id_ue=<? echo $code_ue;?>','ajout');
			//		load_page('listequipe.php?id_ue=<? echo $code_ue;?>','listcoconcepteur');
			
				
			}
		}
			
	);
//	alert('<? echo $code_ue;?>');
	//load_page('addequipe.php?id_ue=<? echo $code_ue;?>','ajout');
	//load_page('listequipe.php?id_ue=<? echo $code_ue;?>','listcoconcepteur');
}

function alertMsg()
{

}
</script>





<form id="addcoconcepteur" action="" enctype="multipart/form-data">

<table>
  			

 <tr align="left"> 
                  <td colspan="3"> <strong><img src="images/navi_arerow.gif" width="6" height="21" align="absmiddle" /> 
Membre de l'&eacute;quipe :</strong></td>
                </tr>
      
				
<tr>
<td>Nom</td><td><input class="validate[required,custom[onlyLetter],length[0,100]] text-input" name="nom"></td>
</tr>

<tr>
<td>Pr&eacute;nom</td><td><input class="validate[required,custom[onlyLetter],length[0,100]] text-input" name="prenom"></td>
</tr>

<tr>
<td>Fonction</td><td><input class="validate[required,custom[onlyLetter],length[0,100]] text-input" name="fonction"></td>
</tr>

<tr>
<td>Grade</td><td>
	<select class="validate[required]" name="grade" id="grade" maxlength="50">
					<option value="">Choisissez votre Grade</option>
					<?php 
		          $grade = new Grade();
                  $g=$grade->getAllGrade();
				  // Liste des grades
                 while (list($clef,$valeur)=each($g)) 
				     {  if($valeur[0]<10) $valeur[0]="0".$valeur[0];
						echo "<OPTION value=".$valeur[0].">$valeur[2]</OPTION>";
                     }
		        ?>
	</select>
				</td>
</tr>

<tr>
<td>Sp&eacute;cialit&eacute;</td><td><input class="validate[required,custom[onlyLetter],length[0,100]] text-input" name="specialite"></td>
</tr>

<tr>
<td>&Eacute;tablissement</td><td><input class="validate[required,custom[onlyLetter],length[0,100]] text-input" name="id_universite"></td>
</tr>

<tr align="left"> 
        <td colspan="3"> <strong><img src="images/navi_arerow.gif" width="6" height="21" align="absmiddle" /> 
Ins&eacute;rer CV  :</strong>
		</td>
</tr>
<tr>
<td></td>
<td>
		<?php include_once('uploadify/up.php');?>
		<!--<input name="cv" type="file">-->
</td>
</tr>

 <tr align="left"> 
                  <td colspan="3"> <strong><img src="images/navi_arerow.gif" width="6" height="21" align="absmiddle" /> 
Coordonn&eacute;es :</strong></td>
 </tr>
 

<tr>
<td>Adresse :</td><td><input class="validate[required,custom[telephone]] text-input"  name="Adresse"></td>
</tr>
<tr>
<td>Code postal :</td><td><input class="validate[required] text-input"  name="CodePostal"></td>
</tr>

<tr>
<td>Ville :</td><td><input class="validate[required] text-input"  name="Ville"></td>
</tr>

<tr>
<td>Tel:</td><td><input class="validate[required,custom[telephone]] text-input"  name="tel"></td>
</tr>

<tr>
<td>GSM :</td><td><input name="NumMobile" class="validate[required,custom[telephone]] text-input"></td>
</tr>
			
<tr>
<td>Fax :</td><td><input name="NumFax" class="validate[required,custom[telephone]] text-input"></td>
</tr>
			
<tr>
<td>Email</td><td><input name="email" class="validate[required,custom[email]] text-input"></td>
</tr>

<tr>
<td>Site Web</td><td><input name="WebSite" class="validate[required,custom[url]] text-input"></td>
</tr>


<tr>
<td><input type="button" value="Annuler" onclick="reset_page('ajout');" class="button"></td>
<td>
<?
 
	// R�cup�ation de l'id du cours en quesition
	 $projet = new Projet();
	 $id_ue = $projet->getProjetBySession(session_id());
	 //echo $id_ue;


  
?>


<input name="id_ue" value="<?php echo $code_ue;?>" type="hidden">
<input type="button" value="Enregistrer"  id="add" class="button"></td>

</tr>

</table>



</form>